/*  KDevelop 4.3.1
 *  1930.cxx
 *
 * 	Author : Pallab
 * 	Created on: 8:37:11 PM - 2013:1:14
 * 	"I have not failed, I have just found 10000 ways that won't work."
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;


#define foR(i,frm,upto) for( int i=(frm),_i=(upto);(i) < (_i) ; ++i )
#define foD(i,frm,upto) for( int i=(frm),_i=(upto);(i) >= (_i) ; --i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait ( double seconds ) {
    double endtime = clock() + ( seconds * CLOCKS_PER_SEC );
    while ( clock() < endtime ) {
        ;
    }
}
template<class T>
    inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while ( c<33 ) c=getchar();
    while ( c>33 ) {
        if ( c=='-' ) {
            neg=true;
        } else {
            a= ( a*10 ) + ( c-'0' );
        }
        c=getchar();
    }
    return neg?-a:a;
}
class Node {
    private:
    int v,dir;
    public:
    Node() {
        v=dir=0;
    }
    Node ( int v_,int dir_ ) {
        v=v_,dir=dir_;
    }
    inline int getV() {
        return v;
    }
    inline int getDir() {
        return dir;
    }
};
#define upward 0
#define dnward 1
const int MX=10005;
int cityCount,roadCount;
int ivanLive,orlovLive;

vector<Node> adj[MX];
inline void read() {
    //1:
    foR ( i,0,MX ) {
        adj[i].clear();
    }
    //2:
    cityCount=fastIn<int>(),roadCount=fastIn<int>();
    int u,v;
    foR ( i,0,roadCount ) {
        u=fastIn<int>()-1,v=fastIn<int>()-1;
        adj[u].push_back ( Node ( v,upward ) );
        adj[v].push_back ( Node ( u,dnward ) );
    }
    ivanLive=fastIn<int>()-1;
    orlovLive=fastIn<int>()-1;
}

const int INF=1023456789;
int dp[MX][2];
int go ( int curPos,int curDir ) {
    if ( curPos==orlovLive ) {
        return 0;
    }
    int &bst = dp[curPos][curDir],nxtPos,nxtDir;
    if ( bst!=-1 ) return bst;
    bst=INF;
    foR(i,0,SZ(adj[curPos])){
        nxtPos = adj[curPos][i].getV();
        nxtDir = adj[curPos][i].getDir();

        int localBst=go ( nxtPos,nxtDir ) + ( nxtDir==curDir ? 0 : 1 );
        bst=min ( bst,localBst );
    }
    return bst;
}
inline void proc() {

    int bst=INF;
    SET ( dp,-1 );
    bst=min ( bst,go ( ivanLive,upward ) );
    SET ( dp,-1 );
    bst=min ( bst,go ( ivanLive,dnward ) );
    cout<< bst <<"\n";
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    freopen ( "in1", "r", stdin );
    kase = 2;
#endif
    for ( int i=1; i<=kase; ++i ) {
        read();
        proc();
    }
    return 0;
}

// kate: indent-mode cstyle; indent-width 4; replace-tabs on; 
